﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AocsoftSample.PersistModels"
                   namespace="AocsoftSample.PersistModels">

  <class name="Category" table="Category" >
    <id  name="Key" type="Guid" access="property" column="ID">
      <generator class="assigned">
      </generator>
    </id>
    <property name="Name"/>
    <property name="UriCode"/>
    <property name="LangCode"/>
    <property name="Level"/>
    <property name="Type"/>
    <property name="OrderIndex"/>
    <many-to-one name="Parent" column="ParentId" class="Category">

    </many-to-one>
    <set name="Children" inverse="true" cascade="all" >
      <key column="ParentId" foreign-key="fk_Category_ParentNode"/>
      <one-to-many class="Category"/>
    </set>

    <set name="Descendants" table="CategoryHierarchy" inverse="true" >
      <key column="ParentId" foreign-key="fk_HierarchyCategory_ParentNode"/>
      <many-to-many class="Category" column="ChildId" foreign-key="fk_HierarchyCategory_ChildNode" />
    </set>

    <set name="Ancestors" table="CategoryHierarchy" >
      <key column="ChildId" />
      <many-to-many class="Category" column="ParentId" />
    </set>
  </class>

  <class name="Node">
    <id name="Id">
      <generator class="guid"/>
    </id>
    <property name="Name" length="50" not-null="true" unique="true"/>

    <many-to-one name="Parent" class="Node" column="ParentId" />

    <set name="Children" inverse="true" cascade="all" >
      <key column="ParentId" foreign-key="fk_Node_ParentNode"/>
      <one-to-many class="Node"/>
    </set>

    <set name="Descendants" table="NodeHierarchy" inverse="true" >
      <key column="ParentId" foreign-key="fk_HierarchyNode_ParentNode"/>
      <many-to-many class="Node" column="ChildId" foreign-key="fk_HierarchyNode_ChildNode" />
    </set>

    <set name="Ancestors" table="NodeHierarchy" >
      <key column="ChildId" />
      <many-to-many class="Node" column="ParentId" />
    </set>
  </class>
</hibernate-mapping>